clear
set more off
set matsize 2000
set scheme modern

*	Change CD
*	global root         	"..."
	global raw				="$root/raw"
	global output			="$root/output"
	


use "$raw/weimar_final", replace


********************************************************************************
*Figure 3a
********************************************************************************

reg s_nsdap 		s_bigfarms   s_agriculture  	s_protestantism log_pop		i.province_id	i.election  if ostelbien==1 & election > 25, cluster(district_id)

	local coef_main=round(_b[s_bigfarms],.001)
	local t = _b[s_bigfarms]/_se[s_bigfarms]
	local t_round = round(`t',.001)
	local p =2*ttail(e(df_r),abs(`t')) // computes p-value

	if `p'<.01 {
		local signstars = "***"
	}
	else if `p'>=.01 & `p'<.05 {
		local signstars = "**"
	}
	else if `p'>=.05 & `p'<.1 {
		local signstars = "*"
	}
	else if `p'>= .1 {
		local signstars = ""
	}
	
	local string_main= "{&beta}="+"`coef_main'"+"`signstars'"
	display "string_main"

	local t_main = "t=`t_round'"
	display "t_main"

local ytitle "Votes NSDAP (in %)"
local xtitle "Large landowners (in %)"	
binscatter s_nsdap s_bigfarms if ostelbien==1, n(30) control(s_agriculture  	s_protestantism log_pop i.province_id	 i.election) ytitle(`ytitle') xtitle(`xtitle') text(18.6 2.2 "`string_main'", color(black) place(e)) text(18.4 2.2 "`t_main'", color(black) place(e))
graph export "$output/figure3a.pdf", replace


********************************************************************************
*Figure 4b
********************************************************************************
reg s_turnout 		s_bigfarms   s_agriculture  	s_protestantism log_pop		i.province_id	i.election  if ostelbien==1, cluster(district_id)

	local coef_main=round(_b[s_bigfarms],.001)
	local t = _b[s_bigfarms]/_se[s_bigfarms]
	local t_round = round(`t',.001)
	local p =2*ttail(e(df_r),abs(`t')) // computes p-value

	if `p'<.01 {
		local signstars = "***"
	}
	else if `p'>=.01 & `p'<.05 {
		local signstars = "**"
	}
	else if `p'>=.05 & `p'<.1 {
		local signstars = "*"
	}
	else if `p'>= .1 {
		local signstars = ""
	}
	
	local string_main= "{&beta}="+"`coef_main'"+"`signstars'"
	display "string_main"

	local t_main = "t=`t_round'"
	display "t_main"

local ytitle "Turnout (in %)"
local xtitle "Large landowners (in %)"	
binscatter s_turnout s_bigfarms if ostelbien==1, n(40) control(s_agriculture  	s_protestantism log_pop i.province_id	 i.election) ytitle(`ytitle') xtitle(`xtitle') text(85.7 2.2 "`string_main'", color(black) place(e)) text(85.3 2.2 "`t_main'", color(black) place(e))
graph export "$output/figure4b.pdf", replace

sum s_bigfarms
di 1.442774 * r(sd)

sum s_turnout
di .78066496 /r(sd)

********************************************************************************
*Appendix Table A1, part for Weimar Germany
********************************************************************************
sum s_bigfarms if election==28, d
sum s_nsdap if election>25, d



********************************************************************************
*Appendix Table A5
********************************************************************************

eststo dnvp1: reg s_dnvp 		s_bigfarms log_pop  s_agriculture s_protestantism 				i.election  if ostelbien==1, cluster(district_id)
estadd local YearFE		 	"\checkmark"
estadd local Sample			"East Elbia"
estadd local Control 		"\checkmark"
quietly: estadd ysumm


eststo dnvp2: reg s_dnvp 		s_bigfarms log_pop  s_agriculture s_protestantism i.province_id 	i.election  if ostelbien==1, cluster(district_id)
estadd local RegionFE 		"\checkmark"
estadd local YearFE		 	"\checkmark"
estadd local Sample			"East Elbia"
estadd local Control 		"\checkmark"
quietly: estadd ysumm

eststo dnvp3: reg s_dnvp 		s_bigfarms log_pop  s_agriculture s_protestantism i.province_id 	i.election  , cluster(district_id)
estadd local RegionFE 		"\checkmark"
estadd local YearFE		 	"\checkmark"
estadd local Sample			"Weimar"
estadd local Control 		"\checkmark"
quietly: estadd ysumm


local titles " Dep. var. & \multicolumn{3}{c}{Votes DNVP (in \%)} \\" 

#delimit ;
estout dnvp1 dnvp2 dnvp3    using "$output/appendix_tab05.tex", 
	replace 			
	starlevels(* 0.10 ** 0.05 *** 0.01)
	label
	collabels(none) 
	keep (s_bigfarms )
	style(tex) cells(b(star fmt(3)) se(fmt(3) par))
	stats(ymean ysd YearFE RegionFE Control Sample r2  N , fmt(%9.2f %9.2f  %~3s %~3s  %~3s %~3s %9.2f %9.0f) 
	labels("Mean dependent variable" "SD dependent variable" "Election FE" "Province FE" "Further controls" "Sample" "R-squared"  "Observations" ))
	mlabels("" "" "" , span prefix(\multicolumn{@span}{c}{) suffix(}) numbers)
	prehead("\begin{tabularx}{1\textwidth}{Xccc}" "\toprule  `titles' ")
	posthead(" \cmidrule(lr){2-4} ") prefoot("\midrule") postfoot("\bottomrule" "\end{tabularx}");
	#delimit cr
	*/		
	
	

	

********************************************************************************
*Appendix Table A6
********************************************************************************

eststo nsdap1: reg s_nsdap 		s_bigfarms   s_agriculture  	s_protestantism log_pop						i.election  if ostelbien==1 & 	election > 25, cluster(district_id)
estadd local YearFE "\checkmark"
estadd local Sample			"East Elbia"
estadd local Control "\checkmark"
quietly: estadd ysumm

eststo nsdap2: reg s_nsdap 		s_bigfarms   s_agriculture  	s_protestantism log_pop		i.province_id	i.election  if ostelbien==1 & 	election > 25, cluster(district_id)
estadd local RegionFE "\checkmark"
estadd local YearFE "\checkmark"
estadd local Sample			"East Elbia"
estadd local Control "\checkmark"
quietly: estadd ysumm

eststo nsdap3: reg s_nsdap 		s_bigfarms   s_agriculture  	s_protestantism log_pop		i.province_id	i.election  if 					election > 25, cluster(district_id)
estadd local RegionFE "\checkmark"
estadd local YearFE "\checkmark"
estadd local Sample			"Weimar"
estadd local Control "\checkmark"
quietly: estadd ysumm


local titles " Dep. var. & \multicolumn{3}{c}{Votes NSDAP (in \%)} \\" 


#delimit ;
estout nsdap1 nsdap2 nsdap3  using "$output/appendix_tab06.tex", 
	replace 			
	starlevels(* 0.10 ** 0.05 *** 0.01)
	label
	collabels(none) 
	keep (s_bigfarms)
	style(tex) cells(b(star fmt(3)) se(fmt(3) par))
	stats(ymean ysd YearFE RegionFE Control Sample r2  N , fmt(%9.2f %9.2f  %~3s %~3s  %~3s %~3s %9.2f %9.0f) 
	labels("Mean dependent variable" "SD dependent variable" "Election FE" "Province FE" "Further controls" "Sample" "R-squared"  "Observations" ))
	mlabels("" "" "" , span prefix(\multicolumn{@span}{c}{) suffix(}) numbers)
	prehead("\begin{tabularx}{1\textwidth}{Xccc}" "\toprule  `titles' ")
	posthead(" \cmidrule(lr){2-4} ") prefoot("\midrule") postfoot("\bottomrule" "\end{tabularx}");
	#delimit cr
	*/		

********************************************************************************
*Appendix Table A9
********************************************************************************
		
eststo turnout1: reg s_turnout 		s_bigfarms log_pop  s_agriculture s_protestantism 				i.election  if ostelbien==1, cluster(district_id)
estadd local YearFE 		"\checkmark"
estadd local Sample			"East Elbia"
estadd local Control 		"\checkmark"
quietly: estadd ysumm

eststo turnout2: reg s_turnout 		s_bigfarms log_pop  s_agriculture s_protestantism i.province_id 	i.election  if ostelbien==1, cluster(district_id)
estadd local RegionFE 		"\checkmark"
estadd local YearFE 		"\checkmark"
estadd local Sample			"East Elbia"
estadd local Control 		"\checkmark"
quietly: estadd ysumm

eststo turnout3: reg s_turnout 		s_bigfarms log_pop  s_agriculture s_protestantism i.province_id 	i.election  , cluster(district_id)
estadd local RegionFE 		"\checkmark"
estadd local YearFE 		"\checkmark"
estadd local Sample			"Weimar Germany"
estadd local Control 		"\checkmark"
quietly: estadd ysumm


local titles " Dep. var. & \multicolumn{3}{c}{Turnout (in \%)} \\" 

#delimit ;
estout turnout1 turnout2 turnout3 using "$output/appendix_tab09.tex", 
	replace 			
	starlevels(* 0.10 ** 0.05 *** 0.01)
	label
	collabels(none) 
	keep (s_bigfarms)
	style(tex) cells(b(star fmt(3)) se(fmt(3) par))
	stats(ymean ysd YearFE RegionFE Control Sample r2  N , fmt(%9.2f %9.2f  %~3s %~3s  %~3s %~3s %9.2f %9.0f) 
	labels("Mean dependent variable" "SD dependent variable" "Election FE" "Province FE" "Further controls" "Sample" "R-squared"  "Observations" ))
	mlabels("" "" "" , span prefix(\multicolumn{@span}{c}{) suffix(}) numbers)
	prehead("\begin{tabularx}{1\textwidth}{Xccc}" "\toprule  `titles' ")
	posthead(" \cmidrule(lr){2-4} ") prefoot("\midrule") postfoot("\bottomrule" "\end{tabularx}");
	#delimit cr
	*/		
	
********************************************************************************
*Appendix Table A11
********************************************************************************


foreach year in 28 30 31 32 33 {
eststo reg`year': reg s_nsdap  s_bigfarms log_pop  s_agriculture s_protestantism  i.province_id if ostelbien==1 & election==`year', cluster(district_id)
estadd local Controls "\checkmark"
estadd local RegionFE "\checkmark"
quietly: estadd ysumm
}


local titles "\multicolumn{6}{l}{Dep. var.: Vote NSDAP (in \%)} \\ Election  & 1928 & 1930 & 1932/07 & 1932/11 & 1933 \\" 
#delimit ;
estout reg28 reg30 reg31 reg32 reg33  using "$output/appendix_tab11.tex", 
	replace 			
	starlevels(* 0.10 ** 0.05 *** 0.01)
	label
	collabels(none) 
	keep ( s_bigfarms)
	style(tex) cells(b(star fmt(3)) se(fmt(3) par))
	stats(ymean ysd Controls RegionFE r2  N , fmt(%9.2f %9.2f %~3s %~3s %9.2f %9.0f) 
	labels("Mean dependent variable" "SD dependent variable" "Controls" "Province FE" "R-squared"  "Observations" ))
	mlabels("" "" "" "" "", span prefix(\multicolumn{@span}{c}{) suffix(}) numbers)
	prehead("\begin{tabularx}{1\textwidth}{Xccccc}" "\toprule `titles' ")
	posthead(" \cmidrule(lr){2-6} ") prefoot("\midrule") postfoot("\bottomrule" "\end{tabularx}");
	#delimit cr
	*/				
	

	

	
